package service

import "usad2/app/dao"

type GetService func(name string )Service
var RegisterMap = map[string]GetService{}

func registerService(name string, getService GetService)  {
	RegisterMap[name] = getService
}
func newBaseService(name string) BaseService {
	return  BaseService{Name: name, Dao: &dao.BaseDao{Name: name}}
}

func NewService(name string) (service Service) {

	if getService,ok := RegisterMap[name]; ok {
		service = getService(name)
	} else{
		service = &BaseService{Name: name, Dao: &dao.BaseDao{Name: name}}
	}
	return  service
	//switch name {
	//case "cert":
	//	service = &CertService{
	//		BaseService:     newBaseService(name),
	//		CertTextService: NewService("cert_text"),
	//	}
	//case "ppt" :
	//	service = &PptService{
	//		BaseService:newBaseService(name),
	//		PptTextService : NewService("ppt_text"),
	//	}
	//default:
	//	service1 := newBaseService(name)
	//	service = &service1
	//}
	//return service
}

